Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mediatek: filogic: wax220: support factory image #13015

Closed
wants to merge 1 commit into from

Conversation

agners
Copy link
Contributor

@agners agners commented Jun 30, 2023

Enable building a factory image which can be flashed through the OEM
firmware's web interface. It seems that the web interface requires a
minimum file size of 10MiB, otherwise it will not accept the image.

The update image is a regular sysupgrade tarball packed in a Netgear
encrypted image. The Netgear encrypted image is the same as used in
WAX202 or WAX206, including the encryption keys and IV.

@github-actions github-actions bot added the target/mediatek pull request/issue for mediatek target label Jun 30, 2023
@agners agners force-pushed the support-factory-image-for-wax220 branch from 000bc52 to 912522f Compare June 30, 2023 10:34
@github-actions github-actions bot added the core packages pull request/issue for core (in-tree) packages label Jun 30, 2023
@agners
Copy link
Contributor Author

agners commented Jun 30, 2023

/cc @Flole998

@agners agners force-pushed the support-factory-image-for-wax220 branch from 912522f to 2c0b0d8 Compare June 30, 2023 13:58
@agners agners changed the title filogic: wax220: support factory image mediatek: filogic: wax220: support factory image Jun 30, 2023
@mrkiko
Copy link
Contributor

mrkiko commented Jun 30, 2023

Why the u-boot envtools config change?

@agners
Copy link
Contributor Author

agners commented Jun 30, 2023

Why the u-boot envtools config change?

The order of the MTD partitions changed, which changes the mtd number.

@hauke
Copy link
Member

hauke commented Jul 1, 2023

Why the u-boot envtools config change?

The order of the MTD partitions changed, which changes the mtd number.

Is the u-boot environment partition change also needed when you install it like it was done without your patch? Is it broken in general for this device or is this related to your changes?

@agners
Copy link
Contributor Author

agners commented Jul 1, 2023

Is the u-boot environment partition change also needed when you install it like it was done without your patch? Is it broken in general for this device or is this related to your changes?

Whoops this change got squashed into the wrong commit. I'll fit it, thanks for bringing this up.

@agners agners force-pushed the support-factory-image-for-wax220 branch 2 times, most recently from 8e75455 to dcb64c2 Compare July 1, 2023 19:13
@github-actions github-actions bot removed the core packages pull request/issue for core (in-tree) packages label Jul 2, 2023
@agners agners force-pushed the support-factory-image-for-wax220 branch 2 times, most recently from 9d2cc50 to 8d901b2 Compare July 4, 2023 22:58
@agners
Copy link
Contributor Author

agners commented Jul 4, 2023

Tested on a WAX220 with FW 1.0.3.0: Update to OpenWrt using the factory image works.

The initramfs doesn't seem to require special padding, so dropping the board specific build script.

@agners agners marked this pull request as ready for review July 4, 2023 23:08
@agners agners marked this pull request as draft July 5, 2023 00:03
@agners
Copy link
Contributor Author

agners commented Jul 5, 2023

While OpenWrt starts successfully, I realized that the rootfs_data UBI volume is missing when updating via OEM firmware. The downstream sysupgrade code has that part commented out 🙈

if [ "y" = "n" ]; then                                     
# create rootfs_data for non-ubifs rootfs                  
if [ "$rootfs_type" != "ubifs" ]; then                     
        if ! ubimkvol /dev/$ubidev -N rootfs_data -m; then 
                echo "cannot initialize rootfs_data volume"
                return 1                                   
        fi                                                 
fi                                                         
fi                                                         

Not sure how to fix this, maybe a custom boot script can be added to create a rootfs_data UBI volume if missing on first boot?

@agners agners force-pushed the support-factory-image-for-wax220 branch from 8d901b2 to 3a7f9d1 Compare July 5, 2023 00:57
@agners agners marked this pull request as ready for review July 5, 2023 00:58
@agners
Copy link
Contributor Author

agners commented Jul 5, 2023

Not sure how to fix this, maybe a custom boot script can be added to create a rootfs_data UBI volume if missing on first boot?

I've added target/linux/mediatek/filogic/base-files/lib/preinit/75_rootfs_prepare to address this issue. I hope this is an acceptable work around.

@agners agners force-pushed the support-factory-image-for-wax220 branch from 3a7f9d1 to a6ab740 Compare July 6, 2023 22:22
@Flole998
Copy link
Contributor

Flole998 commented Jul 7, 2023

This code will also run if openwrt is started as initramfs, right? That's not a good idea, the initramfs should leave the onboard flash memory untouched unless the user explicitly modifies it (by using sysupgrade command for example).

@agners
Copy link
Contributor Author

agners commented Jul 7, 2023

This code will also run if openwrt is started as initramfs, right?

As per my testing, it appears not. But I don't know why 🙈 . The script is there (/lib/preinit/75_rootfs_prepare), and I remove the volume, so it really should create it. But I don't see a message in the boot log, and the volume isn't being created when booting the initramfs. I am not exactly sure why it works. Note I took inspiration from target/linux/bcm4908/base-files/lib/preinit/75_rootfs_prepare, which also does not have a protection.

To be sure, we could add this:

[ "$INITRAMFS" = "1" ] || boot_hook_add preinit_main rootfs_prepare

@agners agners force-pushed the support-factory-image-for-wax220 branch from a6ab740 to 1263562 Compare July 7, 2023 09:47
@Flole998
Copy link
Contributor

Flole998 commented Jul 7, 2023

I'd suggest figuring out why it's not running on an initramfs to avoid adding unnecessary code.

@agners
Copy link
Contributor Author

agners commented Jul 7, 2023

I'd suggest figuring out why it's not running on an initramfs to avoid adding unnecessary code.

Yeah, I am trying, but so far didn't made any progress. A early "echo" in rootfs_prepare just doesn't get called in the initrmafs case. Any hints how to debug this?

@agners
Copy link
Contributor Author

agners commented Jul 7, 2023

Ok, I think I understand now: package/base-files/files/lib/preinit/70_initramfs_test tests if this is a initramfs and breaks the processing of the hooks. So essentially everything hook registered in 70+ isn't executed. So I think we can rely on this, do you agree?

@Flole998
Copy link
Contributor

Flole998 commented Jul 7, 2023

Yes, it seems to be designed exactly for this. Although this is more difficult to understand, it seems like it's exactly what's wanted in this case.

@agners agners force-pushed the support-factory-image-for-wax220 branch from 1263562 to a82ac65 Compare July 7, 2023 11:49
@agners
Copy link
Contributor Author

agners commented Jul 7, 2023

Yes, it seems to be designed exactly for this. Although this is more difficult to understand, it seems like it's exactly what's wanted in this case.

I've removed the INITRAMFS test again and added a note in the commit message.

Thanks for the review! 🙏

Enable building a factory image which can be flashed through the OEM
firmware's web interface. It seems that the web interface requires a
minimum file size of 10MiB, otherwise it will not accept the image.

The update image is a regular sysupgrade tarball packed in a Netgear
encrypted image. The Netgear encrypted image is the same as used in
WAX202 or WAX206, including the encryption keys and IV.

This adds a script which creates the rootfs_data volume on first
startup. This is required since the OEM firmware's sysupgrade scripts
do not create such a paritition. Note that any script ordered after
70_initramfs_test will not get executed on initramfs. Hence this new
script 75_rootfs_prepare won't create the rootfs_data volume when
using the recovery initramfs.

Also, this deletes the kernel_backup and rootfs_backup volumes in case
we have to create the rootfs_data volumes. This makes sure that
OpenWrt is the actual backup firmware instead of the stock firmware.

References in WAX220 GPL source:
https://www.downloads.netgear.com/files/GPL/WAX220-V1.0.2.8-gpl-src.tar.gz

* package/base-files/files/lib/upgrade/nand.sh:186
  Creation of rootfs_data is disabled

* Uboot-upstream/board/mediatek/common/ubi_helper.c
  Automatic creation of UBI backup volumes

Signed-off-by: Stefan Agner <stefan@agner.ch>
@agners agners force-pushed the support-factory-image-for-wax220 branch from a82ac65 to f77260e Compare July 13, 2023 14:42
@agners
Copy link
Contributor Author

agners commented Jul 13, 2023

I've also tested this also with CONFIG_HAS_TESTING_KERNEL=y set, along with #13017. I've installed the factory image also on a new unit, things seem to work as expected: The image gets flashed to kernel and rootfs volume, and the rootfs_data volume gets created on first boot.

I've added initial documentation for this platform, see https://openwrt.org/toh/netgear/wax220.

@dangowrt, since you reviewed/merged the initial WAX220 support: Could you maybe have a look if this looks fine to you? There is also the cleanup PR #13017.

@blocktrron
Copy link
Member

Merged to my staging tree - thanks!

@blocktrron blocktrron closed this Aug 2, 2023
@agners
Copy link
Contributor Author

agners commented Aug 22, 2023

@blocktrron thanks for merging! Do you have an estimate when this commit will appear on main (and therefor make it into snapshot releases?)

@blocktrron
Copy link
Member

Done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
target/mediatek pull request/issue for mediatek target
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants